import { _decorator, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Instruction')
export class Instruction extends Component {

    ndBG
    ndBoard
    lbMsg

    protected onLoad(): void {
        console.log("instruction onload", this.node.worldPosition)

        this.ndBG = this.node.getChildByName("BG");
        // this.ndBoard = this.node.getChildByName("Board");
        // this.lbMsg = this.ndBoard.getChildByName("Label").getComponent(Label)

        //this.node.setWorldPosition(this.node.worldPosition.x , this.node.worldPosition.y ,0)
        
    }


    protected onEnable(): void {
        this.ndBG.on(Node.EventType.TOUCH_END, this.onButtonCloseWindow, this);
        console.log("Instruction onEnable",this.node.worldPosition);

        this.node.setWorldPosition(this.node.worldPosition.x , this.node.worldPosition.y ,0)
    }

    protected onDisable(): void {

        this.ndBG.off(Node.EventType.TOUCH_END, this.onButtonCloseWindow, this);
        
    }


    init(msg, worldPosition){
        console.log("instruction init", msg, worldPosition)
        this.node.getChildByName("Board").getChildByName("Label").getComponent(Label).string = msg
        this.node.setWorldPosition(worldPosition.x + 50, worldPosition.y - 50,0)


    }


    start() {


    }

    update(deltaTime: number) {
        
    }



    onButtonCloseWindow() {
        this.node.active = false;
    }
}


